package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductSkuService;
import com.spzx.product.api.dto.ProductSkuVo;
import com.spzx.product.api.dto.SkuPriceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 服务降级处理
 *
 */
@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductSkuService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductSkuService create(Throwable throwable) {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new RemoteProductSkuService()
        {
            @Override
            public R<ProductSkuVo> getProductSku(Long skuId,String source) {
                return R.fail("获取商品sku失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SkuPriceVo>> getSkuPriceList(List<Long> skuIdList, String source) {
                return R.fail("获取商品sku实时价格失败:" + throwable.getMessage());
            }

            @Override
            public R<SkuPriceVo> getSkuPrice(Long skuId, String source) {
                return R.fail("获取商品sku价格失败:" + throwable.getMessage());
            }

        };
    }
}